import 'package:flutter/material.dart';

///table
class TableDemo1 extends StatefulWidget {
  const TableDemo1({Key? key}) : super(key: key);

  @override
  _TableDemo1State createState() => _TableDemo1State();
}

class _TableDemo1State extends State<TableDemo1> {
  List<Map> _list = [];

  @override
  void initState() {
    for (int i = 0; i < 10; i++) {
      _list.add({
        "name": "hello flutter $i",
        "gender": i % 2 == 0 ? "男" : "女",
      });
    }
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("tableDemo1"),
        centerTitle: true,
      ),
      body: Padding(
        padding: EdgeInsets.all(10),
        child: Table(
          border: TableBorder.all(color: Colors.grey),
          children: _list
              .map((e) => TableRow(
                    children: [
                      Text(e["name"]),
                      Text(e["gender"]),
                    ],
                  ))
              .toList(),
        ),
      ),
    );
  }
}
